package cn.lytcom.architecture.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;

import com.komi.slider.ISlider;
import com.komi.slider.SliderConfig;
import com.komi.slider.SliderUtils;
import com.komi.slider.Utils;
import com.komi.slider.position.SliderPosition;

import cn.lytcom.architecture.R;

/**
 * Created by lytcom on 2017/5/14.
 */

public abstract class SliderActivity extends BaseActivity {

    protected SliderConfig mSliderConfig;
    protected ISlider mSlider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initSlideConfig();
        mSlider = SliderUtils.attachActivity(this, mSliderConfig);

        /*
        Note: activity of manifest need to override the configured theme: android:windowIsTranslucent,
        otherwise slide open the background is black.

        <style name="ActivityTheme" parent="Theme.AppCompat.Light.DarkActionBar">
           <item name="android:windowIsTranslucent">true</item>
        </style>

        If the device is greater than the version of android L, you can use the following method instead:

        SliderUtils.attachActivity(this, mSliderConfig);
        Utils.convertActivityToTranslucent(activity)
         */
        Utils.convertActivityToTranslucent(this);
    }

    protected void initSlideConfig() {
        mSliderConfig = new SliderConfig.Builder()
            .primaryColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
            .secondaryColor(Color.TRANSPARENT)
            .position(getPosition())
            .edge(false)
            .build();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mSlider != null) {
            mSlider.slideExit();
        }
    }

    protected SliderPosition getPosition() {
        return SliderPosition.LEFT;
    }
}
